const https = require('https')
const config = require('../config.js')
/**
 * Reference https://developers.weixin.qq.com/miniprogram/dev/api/api-login.html#wxloginobject
 */
async function getSession(code) {
  const wxUrl = 'https://api.weixin.qq.com/sns/jscode2session'
  const url = `${wxUrl}?appid=${config.appId}&secret=${config.appSecret}&js_code=${code}&grant_type=authorization_code`
  return await https.get(url)
}

module.exports = {
  getSession
}